/*
 * Line.cpp
 *
 *  Created on: Jul 3, 2009
 *      Author: kurt
 */

#include "Line.h"
#include "DrawingCanvas.h"
#include "Types.h"
#include <pspgu.h>
#include <pspgum.h>
#include <sstream>
using namespace std;
using namespace objdraw;
Line::~Line() 
{
	
}

Line::Line() 
{
	start = end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
Line::Line(float x1, float y1, float x2, float y2, DrawingCanvas * c)
{
	start = Location(x1,y1);
	end = Location(x2,y2);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
Line::Line(Location _start, Location _end, DrawingCanvas * c)
{
	start = _start;
	end = _end;
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
Line::Line(const Line & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
void Line::render()
{
	if(hidden) return;
	
	sceGuDisable(GU_TEXTURE_2D);
	sceGuDisable(GU_DEPTH_TEST);
	
	Vertex * points = (Vertex *)sceGuGetMemory(sizeof(Vertex) * 2);
	points[0].x = start.x;
	points[0].y = start.y;
	points[0].z = 0.0f;
	points[0].color = color.gu_c();
	
	points[1].x = end.x;
	points[1].y = end.y;
	points[1].z = 0.0f;
	points[1].color = color.gu_c();
	
	sceGuDrawArray(GU_LINES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, points);
	
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_DEPTH_TEST);
}
string Line::toString()
{
	stringstream rstr("Drawable1DInterface: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}
